import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/nodata_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';

import '../../components/gradient_linear_progressbar.dart';
import 'milepost_controller.dart';

class MilepostView extends GetView{

  MilepostController controller = Get.put(MilepostController());

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      // appBar: BaseAppBar(
      //   preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
      //   child: Text('里程碑'),
      // ),
      body: GetBuilder<MilepostController>(builder: (_){
        return EasyRefresh.custom(
          emptyWidget: controller.model?.data==null?NoDataPage():null,
          onRefresh: ()=>controller.onRefresh(),
          slivers: [
            SliverList(
              delegate: _mySliverChildBuilderDelegate(),
            ),
          ],
        );
      }),
    );
  }

  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {
        return Column(
          children: [
            Container(
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.only(left: 15,right: 15),
              height: 40,
              color: Colors.grey[200],
              child:Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,

                children: [
                  Text('${controller.model?.data?[index].name}'),
                  Center(
                    child: Container(
                      // alignment: Alignment.center,
                      padding: EdgeInsets.only(top: 15),
                      // color: Colors.yellow,
                        width: 150,
                      child:GradientLinearProgressBar(
                          strokeCapRound: true,
                          strokeWidth: 5,
                          colors: [
                            Colors.blueAccent,
                            AppColor.themeColor,
                          ],
                          backgroundColor: AppColor.lineColor,
                        value: double.parse('${controller.model!.data![index].progress! /100}'),)
                      // LinearProgressIndicator(
                      //   value:double.parse('${controller.model!.data![index].progress! /100}') ,color: AppColor.themeColor,
                      // ),
                    ),
                  ),
                  Text('${controller.model?.data?[index].progress}%',style: TextStyle(
                    fontSize: 12,color: AppColor.themeColor
                  ),),

                ],
              ),
            ),
            ListView.builder(shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (BuildContext context, int a) {
                return Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: Get.width,
                      color: Colors.white,
                      padding: EdgeInsets.all(15),
                      child:Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('${controller.model?.data?[index].tasks?[a].name}'),
                          Text('${controller.model?.data?[index].tasks?[a].progress}%')
                        ],
                      ),
                    ),
                    Container(
                      height: 0.5,
                      color: AppColor.lineColor,
                    )
                  ],
                );
              },itemCount: controller.model?.data?[index].tasks?.length??0,)
          ],
        );
      },
      childCount: controller.model?.data?.length??0,
    );
  }


}